import { teacherList } from "./teacherLisst";
const classList1 = [
    {
        id: 1,
        couserName: "003",
        teacherName: 'abc',
        couresTypes: 1,
        createTime: "2024-05-17T03:39:37.000+00:00",
        updateTime: "2024-05-17T03:39:37.000+00:00"
    },
    {
        id: 2,
        couserName: "004",
        teacherName: 'abc',
        couresTypes: 1,
        createTime: "2024-05-17T03:47:51.000+00:00",
        updateTime: "2024-05-17T03:47:51.000+00:00"
    }
]
const classList2 = [
    {
        id: 101,
        couserName: "003",
        teacherName: 'abc',
        couresTypes: 2,
        createTime: "2024-05-17T03:39:37.000+00:00",
        updateTime: "2024-05-17T03:39:37.000+00:00"
    },
    {
        id: 102,
        couserName: "004",
        teacherName: 'abc',
        couresTypes: 2,
        createTime: "2024-05-17T03:47:51.000+00:00",
        updateTime: "2024-05-17T03:47:51.000+00:00"
    }
]


export default [
    //获取信息 必修课
    {
        url: '/course/compulsory',
        method: 'get',
        response: (config) => {

            // 从请求头中获取 Authorization 值
            const authorization = config.headers.Authorization;
            // 从请求参数中获取 page 和 pageSize 值
            let page = config.query.page
            let pageSize = config.query.pageSize
            // 模拟数据查询和分页处理

            const totalCount = classList1.length;
            const startIndex = (page - 1) * pageSize;
            const endIndex = startIndex + pageSize;
            const data = classList1.slice(startIndex, endIndex);
            return {
                code: 200,
                messages: '获取教师信息成功',
                data: {
                    courses: {
                        total: totalCount,
                        rows: data
                    }
                }
            };
        }
    },
    {
        url: '/course/elective',
        method: 'get',
        response: (config) => {
            // 从请求头中获取 Authorization 值
            const authorization = config.headers.Authorization;
            // 从请求参数中获取 page 和 pageSize 值
            const { page, pageSize } = config.query;
            // 模拟数据查询和分页处理
            const totalCount = classList2.length;
            const startIndex = (page - 1) * pageSize;
            const endIndex = startIndex + pageSize;
            const data = classList2.slice(startIndex, endIndex);
            return {
                code: 200,
                messages: '获取教师信息成功',
                data: {
                    courses: {
                        total: totalCount,
                        rows: data
                    }
                }
            };
        }
    },
    {
        url: '/course',
        method: 'post',
        response: (config) => {
            // 从请求头中获取 Authorization 值
            const authorization = config.headers.Authorization;

            // 从请求体中获取课程数据
            const { couserName, couresTypes, teacherName } = config.body;

            // 模拟创建课程的逻辑
            if (Number(couresTypes) == 1) {
                const newCourse = {
                    id: classList1.length + 1,
                    couserName: couserName,
                    teacherName: teacherName,
                    couresTypes: parseInt(couresTypes),
                    createTime: new Date().toISOString(),
                    updateTime: new Date().toISOString()
                };
                
                classList1.push(newCourse);
            }
            if (Number(couresTypes) == 2) {
                const newCourse = {
                    id: classList2.length + 101,
                    couserName: couserName,
                    teacherName: teacherName,
                    couresTypes: parseInt(couresTypes),
                    createTime: new Date().toISOString(),
                    updateTime: new Date().toISOString()
                };
                
                classList1.push(newCourse);
            }

            return {
                code: 200,
                messages: '新增成功'
            };
        }
    },
    {
        url: '/course',
        method: 'delete',
        response: (config) => {
            // 从请求头中获取 Authorization 值
            const authorization = config.headers.Authorization;

            // 从请求体中获取课程 ID
            const id = config.query.id;

            // 模拟删除课程的逻辑
            const index = classList1.findIndex(course => course.id === parseInt(id));
            const index1 = classList2.findIndex(course => course.id === parseInt(id))
            if (index !== -1) {
                classList1.splice(index, 1);
                return {
                    code: 200,
                    messages: '删除成功'
                };
            }
            if (index1 !== -1) {
                classList2.splice(index, 1);
                return {
                    code: 200,
                    messages: '删除成功'
                };
            }
            else {
                return {
                    code: 400,
                    messages: '获取失败'
                };
            }
        }
    },
    {
        url: '/course',
        method: 'patch',
        response: (config) => {
            // 从请求头中获取 Authorization 值
            const authorization = config.headers.Authorization;

            // 从请求体中获取课程 ID 和要更新的信息
            const { id, teacherId, ...updateData } = config.body;
            // 模拟更新课程的逻辑
          
            const course1 = classList1.find(item => item.id === parseInt(id));
            if (course1) {
                Object.assign(course1, updateData);
                return {
                    code: 200,
                    messages: '修改成功'
                };
            }
            if (!course1) {
                let course2 = classList2.find(item => item.id === parseInt(id));
                if (course2) {
                    Object.assign(course2, updateData);
                    return {
                        code: 200,
                        messages: '修改成功'
                    };
                } else {
                    return {
                        code: 400,
                        messages: '获取失败'
                    };
                }

            }
            else {
                return {
                    code: 400,
                    messages: '获取失败'
                };
            }
        }
    }
]